FcText
Various text utilities and wrappers for making kotlin minecraft modding more text-expressive
Author
fzzyhmstrs
Since
0.2.0
See also
Samples
import com.mojang.brigadier.LiteralMessage
import me.fzzyhmstrs.fzzy_config.fcId
import me.fzzyhmstrs.fzzy_config.util.FcText
import me.fzzyhmstrs.fzzy_config.util.FcText.bold
import me.fzzyhmstrs.fzzy_config.util.FcText.command
import me.fzzyhmstrs.fzzy_config.util.FcText.descLit
import me.fzzyhmstrs.fzzy_config.util.FcText.lit
import me.fzzyhmstrs.fzzy_config.util.FcText.text
import me.fzzyhmstrs.fzzy_config.util.FcText.tooltip
import me.fzzyhmstrs.fzzy_config.util.FcText.transLit
import me.fzzyhmstrs.fzzy_config.util.FcText.translate
import me.fzzyhmstrs.fzzy_config.util.FcText.underline
import me.fzzyhmstrs.fzzy_config.util.Translatable
import net.minecraft.registry.RegistryKeys
import net.minecraft.registry.tag.TagKey
import net.minecraft.util.Identifier
import net.minecraft.util.math.ChunkPos
import java.util.*
fun main() {
//sampleStart
//FcText has wrappers for the standard Text methods, historically used for porting
val standardText = FcText.literal("Normal text")
val translateText = FcText.translatable("my.translatable.text")
val fallbackText = FcText.translatableWithFallback("my.translatable.text", "My Fallback")
val stringifiedText = FcText.stringified("my.stringified.text", TagKey.of(RegistryKeys.ITEM, "arg_requiring_stringification".fcId()))
val emptyText = FcText.empty()
val appendedText = FcText.appended(standardText, fallbackText)
//several extension functions for converting common MC and Java objects into text
val idText = Identifier("stick").text()
val uuidText = UUID.fromString("732bf411-5bb5-4f5d-8ef0-feb45d6032ee").text()
val dateText = Date().text()
val messageText = LiteralMessage("Example Message").text()
val chunkPosText = ChunkPos(4, 4).text()
//string extension functions for simple text-ification of string literals
val stringLit = "My Cool String".lit()
val stringTranslate = "my.cool.string".translate() // can add args too
// simple example class that implements Translatable
class TranslatableExample: Translatable {
override fun translationKey(): String {
return "example.translatable.translation"
}
override fun descriptionKey(): String {
return "example.translatable.translation.desc"
}
}
//provide translations and descriptions for anything, particularly hooking into Translatable
val myTranslatableThing = TranslatableExample()
// translates anything, first checking if the thing is Translatable and using that translation if found, otherwise it translates the fallback key
val anyTranslate = myTranslatableThing.translation("my.fallback.translation")
//translate anything, first checking if the thing is Translatable and using that translation if found, otherwise it provides the fallback string literally
val anyTransLit = myTranslatableThing.transLit("Fallback Message")
// describes anything, first checking if the thing is Translatable and using that description if found, otherwise it translates the fallback key
val anyDescription = myTranslatableThing.description("my.fallback.translation.desc")
//describes anything, first checking if the thing is Translatable and using that description if found, otherwise it provides the fallback string literally
val anyDescLit = myTranslatableThing.descLit("Fallback Description")
//easily add common styling and context actions with extensions
val myCoolText = "text.with.context".translate().bold().underline().tooltip("text.with.context.tooltip".translate()).command("/gamemode creative")
//sampleEnd
}
Functions
Describes anything (In enchantment description style, or for tooltips, for example). If the thing is Translatable, it will use the built-in description, otherwise it will use the fallback literally
Describes anything (In enchantment description style, or for tooltips, for example). If the thing is Translatable, it will use the built in description, otherwise it will translate the fallback key
Describes anything (In enchantment description style, or for tooltips, for example). If the thing is Translatable, it will use the built-in description, otherwise it will use the fallback literally
Strikes through the receiver text
Wrapper method around Text.stringified. A backwards compatibility holdover from porting older versions
Extension function for converting Messages into Texts in a kotlin style
Extension function for converting Dates into Texts in a kotlin style
Extension function for converting UUIDs into Texts in a kotlin style
Extension function for converting Identifiers into Texts in a kotlin style
Extension function for converting ChunkPos into Texts in a kotlin style
Wrapper method around Text.translatable. A backwards compatibility holdover from porting older versions
Wrapper method around Text.translatableWithFallback. A backwards compatibility holdover from porting older versions
Translates anything. If the thing is Translatable, it will use the built-in translation, otherwise it will translate the fallback key
Translates anything. If the thing is Translatable, it will use the built in translation, otherwise it will use the fallback literally
Translates anything. If the thing is Translatable, it will use the built in translation, otherwise it will use the fallback literally